package com.systemic.core;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @ClassName: ResponseResult
 * @Description:
 * @Author:
 * @CreateTime: 2023-12-26 20:13
 * @Version:
 **/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ResponseResult<T> implements Serializable {
    private static final long serialVersionUID = 8041766238120354183L;

    /* 状态响应码 */
    private Integer code;
    /* 状态响应消息 */
    private String msg;
    /* 状态返回数据 */
    private T data;

    public static <T> ResponseResult<T> success(T data) {
        return ResponseResult.<T>builder()
                .msg(ResponseStatus.SUCCESS.valueZh)
                .code(ResponseStatus.SUCCESS.bCode)
                .data(data)
                .build();
    }

    public static ResponseResult failed() {
        return failed("失败");
    }

    public static ResponseResult failed(String msg) {
        return failed(ResponseStatus.FAILED.bCode, msg);
    }

    public static ResponseResult failed(Integer code, String msg) {
        return ResponseResult.builder()
                .msg(msg)
                .code(code)
                .build();
    }
}
